package dt.member;

import com.opensymphony.xwork2.ActionSupport;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.SqlMapClientBuilder;

import java.io.IOException;
import java.io.Reader;

public class memberFindAction extends ActionSupport {

	public static Reader reader;  // ���� ��Ʈ���� ���� reader
	public static SqlMapClient sqlMapper; // SqlMapClient API�� ����ϱ� ���� sqlMapper ��ü
	
	private memberVO paramClass;  // �Ķ���͸� ������ ��ü
	private memberVO resultClass; // ���� ��� ���� ������ ��ü
	
	private String name;
	private String jumin1;
	private String jumin2;
	private int memberFindChk;
	
	//����
	public memberFindAction() throws IOException {
		reader = Resources.getResourceAsReader("sqlMapConfig.xml"); //sqlMapConfig.xml ������ ���������� �����´�.
		sqlMapper = SqlMapClientBuilder.buildSqlMapClient(reader); //sqlMapConfig.xml ������ ����� sqlMapper ��ü ��
		reader.close();
	}
	
	public String form() throws Exception {
		//����� 
		return SUCCESS;
	}
	
	public String execute() throws Exception {
		
		// �Ķ���Ϳ� ����Ʈ ��ü ��
		paramClass = new memberVO();
		resultClass = new memberVO();
		
		resultClass = (memberVO) sqlMapper.queryForObject("memberFind", getName());
		
		if(resultClass == null) {
			memberFindChk = 0; // ���ԵǾ� �ִ� �̸��� ����
			return INPUT;
		}
		else {
			if(resultClass.getJumin1().equals(jumin1) && resultClass.getJumin2().equals(jumin2)) {
				memberFindChk = 1; // ȸ���ԵǾ� �ִ� �̸��� �ְ� �ֹι�ȣ1, 2�� ��ġ
				return SUCCESS;
			}
			else {
				memberFindChk = -1; // �̸��� �ֹι�ȣ�� ���� ������
				return INPUT;
			}
		}
	}

	public static Reader getReader() {
		return reader;
	}

	public static void setReader(Reader reader) {
		memberFindAction.reader = reader;
	}

	public static SqlMapClient getSqlMapper() {
		return sqlMapper;
	}

	public static void setSqlMapper(SqlMapClient sqlMapper) {
		memberFindAction.sqlMapper = sqlMapper;
	}

	public memberVO getParamClass() {
		return paramClass;
	}

	public void setParamClass(memberVO paramClass) {
		this.paramClass = paramClass;
	}

	public memberVO getResultClass() {
		return resultClass;
	}

	public void setResultClass(memberVO resultClass) {
		this.resultClass = resultClass;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getJumin1() {
		return jumin1;
	}

	public void setJumin1(String jumin1) {
		this.jumin1 = jumin1;
	}

	public String getJumin2() {
		return jumin2;
	}

	public void setJumin2(String jumin2) {
		this.jumin2 = jumin2;
	}

	public int getMemberFindChk() {
		return memberFindChk;
	}

	public void setMemberFindChk(int memberFindChk) {
		this.memberFindChk = memberFindChk;
	}
	
	
}
